﻿@namespace Microsoft.FluentUI.AspNetCore.Components
@inherits FluentComponentBase
@if (ChildContent == null || Visible)
{
    @* Default *@

    @if (Type == MessageType.MessageBar)
    {
        <div id="@Id" class="@ClassValue" style="@StyleValue" animation="@(FadeIn ? "fadein" : null)" @onfocusin="@PauseTimeout" @onfocusout="@ResumeTimeout">

            @* Icon *@
            <div class="fluent-messagebar-icon">
                <FluentIcon Value="@Icon" Title="@(Content?.Intent.ToAttributeValue())" Color="@_color" />
            </div>

            @* Message *@
            <div class="fluent-messagebar-message">
                @if (!String.IsNullOrEmpty(Title))
                {
                    <span class="title">@((MarkupString)Title)</span>
                }
                @if (ChildContent is not null)
                {
                    @ChildContent
                }
                else
                {
                    @((MarkupString)Content!.Body!)
                }
                @if (Link is not null)
                {
                    <FluentAnchor Href="@(String.IsNullOrEmpty(Link?.Href) ? "#" : Link?.Href)"
                                  Appearance="Appearance.Hypertext"
                                  Target="@(Link?.Target ?? "_blank")"
                                  OnClick="@LinkClickedAsync"
                                  title="Link">
                        @Link?.Text
                    </FluentAnchor>
                }
            </div>
            <div class="fluent-messagebar-container-action">
                @if (ShowPrimaryAction)
                {
                    <FluentButton Appearance="@Appearance.Neutral"
                                  OnClick="@PrimaryActionClickedAsync"
                                  title="Alert action"
                                  Class="fluent-messagebar-action">
                        @PrimaryAction?.Text
                    </FluentButton>
                }
                @if (ShowSecondaryAction)
                {
                    <FluentButton Appearance="@Appearance.Neutral"
                                  OnClick="@SecondaryActionClickedAsync"
                                  title="Alert action"
                                  Class="fluent-messagebar-action">
                        @SecondaryAction?.Text
                    </FluentButton>
                }
                @if (AllowDismiss)
                {
                    <FluentIcon Value="@(new CoreIcons.Regular.Size16.Dismiss())"
                                Color=@Color.Neutral
                                Class="fluent-messagebar-close"
                                OnClick="DismissClicked" />
                }
            </div>
        </div>
    }

    @* Notification *@
    @if (Type == MessageType.Notification)
    {
        <div id="@Id" class="@ClassValue" style="@StyleValue" @onfocusin="@PauseTimeout" @onfocusout="@ResumeTimeout">

            @* Icon *@
            <div class="fluent-messagebar-notification-icon">
                <FluentIcon Value="@Icon"
                            Color="@_color"
                            Title="@(Content?.Intent?.ToAttributeValue())" />
            </div>

            @* Message *@
            @if (!String.IsNullOrEmpty(Title))
            {
                <div class="fluent-messagebar-notification-message" title="@Title">
                    @((MarkupString)(Title))
                </div>
            }

            @* Close *@

            @if (AllowDismiss)
            {
                <div class="fluent-messagebar-notification-close">
                    <FluentIcon Value="@(new CoreIcons.Regular.Size16.Dismiss())"
                                Color=@Color.Neutral
                                Class="fluent-messagebar-notification-close"
                                OnClick="DismissClicked" />
                </div>
            }

            @* Detailed content *@
            <div class="fluent-messagebar-notification-content">
                @ChildContent
                @if (!String.IsNullOrEmpty(Content?.Body))
                {
                    @((MarkupString)Content.Body)
                }
                @if (Link is not null)
                {
                    <FluentAnchor Href="@(String.IsNullOrEmpty(Link?.Href) ? "#" : Link?.Href)"
                                  Appearance="Appearance.Hypertext"
                                  Target="@(Link?.Target ?? "_blank")"
                                  OnClick="@LinkClickedAsync"
                                  title="Link">
                        @Link?.Text
                    </FluentAnchor>
                }
                @if (ShowPrimaryAction)
                {
                    <FluentButton Appearance="Appearance.Neutral"
                                  OnClick="@PrimaryActionClickedAsync"
                                  title="Notification action"
                                  Class="fluent-messagebar-action">
                        @PrimaryAction?.Text
                    </FluentButton>
                }

            </div>

            @* Recorded time *@
            @if (Timestamp != null)
            {
                <div class="fluent-messagebar-notification-time">
                    @((DateTime.Now - Timestamp)?.ToTimeAgo())
                </div>
            }

        </div>
    }
}
